package com.yanchangapp.ui.presenter;

import com.yanchangapp.base.HeadApiRetrofit;
import com.yanchangapp.commom.AppConstant;
import com.yanchangapp.model.bean.POrderCntListBean;
import com.yanchangapp.model.bean.PsOrderListBean;
import com.yanchangapp.model.response.POrderCntListResponse;
import com.yanchangapp.ui.view.OrderCntAtView;
import com.zxl.baselib.bean.response.BaseListResponse;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BaseObserver;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.ui.base.ExceptionHandle;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by apple on 2019-08-02.
 * description:
 */
public class OrderCntAtPresenter extends BasePresenter<OrderCntAtView> {

    public OrderCntAtPresenter(BaseActivity context) {
        super(context);
    }

    public void queryCntList(String keywords){
        HeadApiRetrofit.getInstance().queryCmyContractList(keywords)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<BaseListResponse<POrderCntListBean>>() {
                    @Override
                    public void onNext(BaseListResponse<POrderCntListBean> psOrderListBeanBaseListResponse) {
                        if (psOrderListBeanBaseListResponse.getCode() == AppConstant.REQUEST_SUCCESS){
                            if (getView() != null){
                                getView().queryCntListSuccess(psOrderListBeanBaseListResponse.getData());
                            }
                        }else {
                            if (getView() != null){
                                getView().queryCntListFailure(psOrderListBeanBaseListResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseException exception) {
                        if (getView() != null){
                            getView().queryCntListFailure(exception.getErrorInfo());
                        }
                    }
                });
    }
}
